'use strict';

const Controller = require('egg').Controller;
const garvinLog = require('../extend/index');
class garvinController extends Controller {
  async index() {
    const { ctx } = this;
    garvinLog(ctx.session.counter);
    ctx.body = '<h1>index page</h1>';
  }
  // service
  async getGirls() {
    const { ctx } = this;
    ctx.body = await ctx.service.garvin.getGirl(111);
  }

  // http://localhost:7001/getQuery?name=ngw&age=11
  async getQuery() {
    const { ctx } = this;
    ctx.body = ctx.query;
  }

  // http://localhost:7001/getParam/garvin/11
  async getParam() {
    const { ctx } = this;
    const name = ctx.params.name;
    const age = ctx.params.age;
    ctx.body = 'name->' + name + ' age->' + age;
  }
  // post http
  async postAdd() {
    const ctx = this.ctx;
    ctx.body = {
      status: 200,
      data: ctx.request.body,
    };
  }
}

module.exports = garvinController;
